﻿package geom
{
	import flash.geom.Point;
	
	public class Line extends Object
	{
		private var point1: Point;
		private var point2: Point;
		
        public static function cross(line1:Line, line2:Line):Point
		{
			var x0: Number = (line1.b - line2.b) / (line2.k - line1.k);
			var y0: Number = line2.k * (line1.b - line2.b) / (line2.k - line1.k) + line2.b;
			return new Point(x0, y0);
		}
		
		public function Line(point1:Point, point2:Point)
		{
			this.point1 = point1;
			this.point2 = point2;
		}
		
		public function get k():Number
		{
			return (point2.y - point1.y) / (point2.x - point1.x);
		}
		
		public function get b():Number
		{
			return point1.y - point1.x * (point2.y - point1.y) / (point2.x - point1.x);
		}
		
		public function y(x:Number):Number
		{
			return k * x + b;
		}
	}
}